package com.xius.filter;

import cn.hutool.core.lang.Console;
import org.springframework.beans.factory.annotation.Value;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @ClassName UrlFilter
 * @Description TODO
 * @Author 谭庆伟
 * @Date 2020/5/23 20:57
 * @Version 1.0
 **/
@WebFilter(filterName = "UrlFilter", urlPatterns = "/api/**")
public class UrlFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        Console.log("----------------------->过滤器被创建");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {

        HttpServletRequest req = (HttpServletRequest) servletRequest;
        String requestURI = req.getRequestURI();
        String method = req.getMethod();
        Console.log("请求地址=" + requestURI+",请求的方式=" +method);

        //AntPathMatcher antPathMatcher = new AntPathMatcher();
        filterChain.doFilter(servletRequest, servletResponse);
        //Console.log(openUrl);
        //白名单路径
    }

    @Override
    public void destroy() {

    }
}
